package com.imot.response;



import com.imot.constant.code.ResponseCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;



public class Result<T> implements Serializable {

    private Integer code;

    private String msg;

    private T data;


    public static Result success() {
        Result<Object> result = new Result<>();
        result.setCode(ResponseCode.OK.val());
        result.setMsg(ResponseCode.OK.msg());
        result.setData(null);
        return result;
    }

    public static Result success(ResponseCode code) {
        Result<Object> result = new Result<>();
        result.setCode(code.val());
        result.setMsg(code.msg());
        result.setData(null);
        return result;
    }

    public static Result success(Object data) {
        Result<Object> result = new Result<>();
        result.setCode(ResponseCode.OK.val());
        result.setMsg(ResponseCode.OK.msg());
        result.setData(data);
        return result;
    }

    public static Result success(Integer code, String msg, Object data) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result success(ResponseCode code, Object data) {
        Result<Object> result = new Result<>();
        result.setCode(code.val());
        result.setMsg(code.msg());
        result.setData(data);
        return result;
    }

    public static Result fail() {
        Result<Object> result = new Result<>();
        result.setCode(ResponseCode.SYSTEM_ERROR.val());
        result.setMsg(ResponseCode.SYSTEM_ERROR.msg());
        result.setData(null);
        return result;
    }

    public static Result fail(ResponseCode code) {
        Result<Object> result = new Result<>();
        result.setCode(code.val());
        result.setMsg(code.msg());
        result.setData(null);
        return result;
    }

    public static Result fail(Object data) {
        Result<Object> result = new Result<>();
        result.setCode(ResponseCode.SYSTEM_ERROR.val());
        result.setMsg(ResponseCode.SYSTEM_ERROR.msg());
        result.setData(data);
        return result;
    }

    public static Result fail(Integer code, String msg, Object data) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static Result fail(Integer code, String msg) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
    public static Result fail(ResponseCode code, Object data) {
        Result<Object> result = new Result<>();
        result.setCode(code.val());
        result.setMsg(code.msg());
        result.setData(data);
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
